import { Modal } from 'antd';
import type { ModalProps } from 'antd';
import * as React from 'react';
import type { MutableRefObject } from 'react';
import {useState} from "react";
interface PropsType<T> extends Omit<ModalProps, 'onOk'> {
    onOk: (ref: MutableRefObject<T | undefined>) => void;
}
function withModal<T = any>(modalProps?: ModalProps, slotProps?: any) {
    return function (Slot: React.FC<any>) {
        return (props?: PropsType<T>) => {
            const ref = React.useRef<T>();
            return (
                <div>
                    <Modal
                        wrapClassName="modal-wrap"
                        okText="提交"
                        cancelButtonProps={{ shape: 'round' }}
                        okButtonProps={{ shape: 'round' }}
                        width={600}
                        onCancel={close}
                        {...modalProps}
                        {...props}
                        onOk={() => props?.onOk?.(ref)}
                    >
                        <Slot {...slotProps} ref={ref} close={props?.onCancel} />
                    </Modal>
                </div>
            );
        };
    };

}

export default withModal;
